# Kestrel: An XMPP-based Many-Task Computing Scheduler
# Author: Lance Stout <lancestout@gmail.com>
#
# Copyright 2009-2010 Clemson University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


class Policy(object):
    def __init__(self, kernel):
        """
        The system policy is in charge of accepting or rejecting
        subscription requests from other XMPP agents.

        Events listened for by this module:
          system/access/requested
          system/access/approved

        Events raised by this module:
          system/access/request
          system/access/approve
          system/access/reject
        """
        self.kernel = kernel
        self.events = {'system/access/requested': self.approve_access}
        self.kernel.register(self)

    def approve_access(self, entity):
        """
        Approve or reject a request for access to this system
        from another XMPP agent so that it may send messages
        to the system.
        """
        # If the requester does not meet some criteria, then
        # self.kernel.event('system/access/reject', entity)
        # would be used.
        self.kernel.event('system/access/approve', entity)
        self.kernel.event('system/access/request', entity)
